package com.ymatou.iapi.dguser.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.dguser.parameter.GetUserInfoByLoginIdBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.service.GetUserInfoByLoginIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.utils.DataUtil;
/**
*根据LoginId查用户信息Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserInfoByLoginId{
	private static GetUserInfoByLoginIdBean getuserinfobyloginidBean;
	private static GetUserInfoByLoginIdCall getuserinfobyloginidCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据LoginId查用户信息Test");
	}

	@Before
	public void caseUp() {
		getuserinfobyloginidBean=new GetUserInfoByLoginIdBean();
		getuserinfobyloginidCall=new GetUserInfoByLoginIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuserinfobyloginidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void CheckUserDto(UserCreateBean u,JsonObject u1,int userId){
		Logger.verifyEquals(userId, u1.get("userId").getAsInt(), "验证userId");
		Logger.verifyEquals(u.getMobile(), u1.get("mobile").getAsString(), "验证mobile");
		Logger.verifyEquals(u.getMobileAreaCode(), u1.get("mobileAreaCode").getAsString(), "验证mobileAreaCode");
		Logger.verifyEquals(u.getNickname(), u1.get("nickname").getAsString(), "验证nickname");
		Logger.verifyEquals(u.getLogoUrl(), u1.get("logoUrl").getAsString(), "验证logoUrl");
		Logger.verifyEquals(u.getLoginId(), u1.get("loginId").getAsString(), "验证loginId");
		Logger.verifyEquals(u.getUserGender(), u1.get("gender").getAsInt(), "验证gender");
		Logger.verifyEquals(u.getUserType(), u1.get("userType").getAsInt(), "验证userType");
		Logger.verifyEquals(0, u1.get("userStatus").getAsInt(), "验证userStatus");
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserInfoByLoginId_001() {
		Logger.start(true,"创建新用户，验证报文，成功");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			
			getuserinfobyloginidBean.setLoginId(u.getLoginId());
			getuserinfobyloginidCall.setData(getuserinfobyloginidBean);
			getuserinfobyloginidCall.callService();			
			Logger.verifyEquals(true, getuserinfobyloginidCall.getJsonObject().get("success").getAsBoolean(), "验证success");
			JsonObject u1 = getuserinfobyloginidCall.getJsonObject().getAsJsonObject("userDto");
			CheckUserDto(u, u1, user);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserInfoByLoginId_002() {
		Logger.start(true,"登录id为空");
		try {
			getuserinfobyloginidCall.setData(getuserinfobyloginidBean);
			getuserinfobyloginidCall.callService();			
			Logger.verifyEquals(false, getuserinfobyloginidCall.getJsonObject().get("success").getAsBoolean(), "验证success");
			Logger.verifyEquals("loginId:loginId must", getuserinfobyloginidCall.getString("errorMessage"), "验证errorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserInfoByLoginId_003() {
		Logger.start(true,"登录id不存在");
		try {
			
			getuserinfobyloginidBean.setLoginId("1231313131311111111");
			getuserinfobyloginidCall.setData(getuserinfobyloginidBean);
			getuserinfobyloginidCall.callService();			
			Logger.verifyEquals(false, getuserinfobyloginidCall.getJsonObject().get("success").getAsBoolean(), "验证success");
			Logger.verifyEquals("无法找到此用户信息", getuserinfobyloginidCall.getString("errorMessage"), "验证errorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}